import http from "../utils/http"
import {getStorage} from "../utils/storage"

export const userLogin = (code) => {
  return http.get(`/user/login?code=${code}`)
}

// 获取用户信息
export const reqUserInfo = () => http.get(`/user/userInfo`)

// 上传头像数据保存
export const uploadImage = (headImageUrl) => {
  return new Promise((resolve, reject) => {
    wx.uploadFile({
      filePath: headImageUrl,
      name: 'avatar',
      header: {
        token: getStorage("token")
      },
      url: 'http://localhost:7700/user/upload-avatar',
      success: function(res) {
        resolve(res)
      },
      error: function(res) {
        reject(res)
      }
    })
  }) 
}

// 修改用户信息
export const updateUserInfo = (user) => {
  console.log(user,"user");
  return http.post("/user/setUserInfo", user)
}

// 修改用户默认送达地址
export const setDefaultAddress = (address) => {
  return http.post("/user/setDefaultAddress", address)
}

// 修改用户默认商铺
export const setDefaultStore = (userDefaultStore) => {
  return http.post("/user/setDefaultStore", userDefaultStore)
}